package demo10;

import lombok.Data;

public class GetRankOfNumber {
    public Tree createTree(int data){
        return new Tree(data);
    }
    /**
     * left tree , right tree
     * the root have the left or right node
     * root.node , root.node
     */
    @Data
    public class Tree{
        public int data;
        public Tree leftNode;
        public Tree rightNode;

        public Tree(){}
        // init this  the binaryTree that  can search
        // how to balance , the data can input the 3
        public Tree(int data){
          this.data=data;
        }

        // insert the node
        public void insert(int d){
            if(d<=data){ // 1<=2
                if(leftNode!=null) leftNode.insert(d); //
                else leftNode=new Tree(d); //
            }else{
                if(rightNode!=null) rightNode.insert(d);
                else rightNode = new Tree(d);
            }
        }

        public void inOrder(Tree node){
            // first left ,  mid ,right
            System.out.println(node.data);
            if(node!=null){
                inOrder(node.leftNode);
                inOrder(node);
                inOrder(node.rightNode);
            }

        }



    }

    public class BalanceBinarySearchTree{
        /**
         * how to balance
         */
        public void insert(int data){


        }
        /**
         * how tho search
         */
        public void getRankOfNumber(){

        }
    }

    public class GetRankOfNumberDemo{
        // in the interval of 1 min ,   invoke the method : getRankOfNumber.
        /**
         *   5,1,4,4,5,9,7,13,3
         * getRankOfNumber(1)=0
         * getRankOfNumber(3)=1
         * getRankOfNumber(4)=3
         *
         * count the numbers
         * you can to track every val   in the finally time , so easy!!!
         *   step1: first sort  ,
         *   step2: to count it .
         * you need to track every val  continuously .
         *   step1: try use array .
         *      step1:  insert data to array   continuously
         *
         */
        int[] ints = new int[1];
        public void getRankOfNumber(int number,int x){
            // insert  each number into the array  , ensure
            // when invoke the method:  track(); to invoke the getRankOfNumber
            //Does track() have meaining?
           // finite data Stream ,like array ,
            // when insert data , to judge ,
            // create the variable length array , like arrayList
//            int[] ints = new int[9];
            ints[0]=number;
            int j =0 ;
            for (int i = 0; i < ints.length; i++) {
                if(ints[i]<x){
                    j++;
                }
                if(ints[i]==x){
                    // ensure counts x in the ints
                     int count = counts(ints) -1;
                     j +=count;
                }
            }



        }

        private int counts(int[] ints) {
            return 1;
        }

        public void track(int x){
            // track 5 , track 1 ,track 4 ...
            // x=5
            int[] ints = {5,1,4,4,5,9,7,13,3};
            for (int anInt : ints) {
                getRankOfNumber(anInt,x);
            }
        }

    }
}
